package com.pai4j.common.util;

import com.pai4j.domain.dto.jianlipai.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

/**
 *  简历模版渲染工具类： 将由大模型生成的简历数据解析为HTML格式， 该类主要用于前端渲染简历时，将数据填充到模版中
 *
 * @author: CYM-pai
 * @date: 2025/05/29 20:56
 **/
public class JianLiBotUtil {

    public static ResumeDetail parseJson(String html) {
        Document document = Jsoup.parse(html);
        // 应聘岗位
        String job = getTextById(document, "job");
        String extend = getTextById(document, "extend");
        // 用户信息
        ResumeUser resumeUser = ResumeUser.builder()
                .name(getTextById(document, "name"))
                .baseInfo(getTextById(document, "address"))
                .desc(getTextById(document, "desc"))
                .phone(getTextById(document, "phone"))
                .email(getTextById(document, "email"))
                .build();
        // 专业技能
        String tech = document.getElementById("tech").text();
        // 学历
        List<ResumeEducation> educations = new ArrayList<>();
        Element educationCard1 = document.getElementById("educationCard1");
        Element educationCard2 = document.getElementById("educationCard2");
        if (educationCard1 != null) {
            educations.add(
                    ResumeEducation.builder()
                            .school(getTextById(educationCard1, "school"))
                            .education(getTextById(educationCard1, "education"))
                            .speciality(getTextById(educationCard1, "speciality"))
                            .educationTime(getTextById(educationCard1, "graduation-time"))
                            .build());
        }
        if (educationCard2 != null
                && !"毕业时间".equals(getTextById(educationCard2, "graduation-time2"))
                && !"毕业时间2".equals(getTextById(educationCard2, "graduation-time2"))
                && !"学校名称".equals(getTextById(educationCard2, "school2"))
                && !"学校名称2".equals(getTextById(educationCard2, "school2"))) {
            educations.add(
                    ResumeEducation.builder()
                            .school(getTextById(educationCard2, "school2"))
                            .education(getTextById(educationCard2, "education2"))
                            .speciality(getTextById(educationCard2, "speciality2"))
                            .educationTime(getTextById(educationCard2, "graduation-time2"))
                            .build());
        }
        // 履历列表
        List<ResumeCompany> companies = new ArrayList<>();
        Elements companyElems = document.getElementsByClass("companyItem");
        if (CollectionUtils.isNotEmpty(companyElems)) {
            for (Element companyElem : companyElems) {
                companies.add(ResumeCompany.builder()
                        .time(getTextByClass(companyElem, "layui-timeline-title"))
                        .jobDesc(getTextByClass(companyElem, "companyJobDesc"))
                        .build());
            }
        }
        // 项目信息
        List<ResumeProject> projects = new ArrayList<>();
        Elements projectElems = document.getElementsByClass("jingyan-item");
        if (CollectionUtils.isNotEmpty(projectElems)) {
            for (Element projectElem : projectElems) {
                projects.add(ResumeProject.builder()
                        .name(getTextByClass(projectElem, "jingyan-name"))
                        .role(getTextByClass(projectElem, "jingyan-role"))
                        .time(getTextByClass(projectElem, "jingyan-time"))
                        .tech(getTextByClass(projectElem, "projectTech"))
                        .desc(getTextByClass(projectElem, "projectDesc"))
                        .workContent(getTextByClass(projectElem, "projectWorkContent"))
                        .income(getTextByClass(projectElem, "projectIncome"))
                        .build());
            }
        }
        // 个人总结
        String summary = getTextById(document, "summary");
        return ResumeDetail.builder()
                .job(job)
                .user(resumeUser)
                .professionalSkills(tech)
                .personalSummary(summary)
                .educations(educations)
                .companies(companies)
                .projects(projects)
                .extend(extend)
                .build();
    }

    private static String getTextByClass(Element elem, String className) {
        if (elem == null || StringUtils.isBlank(className)) {
            return "";
        }
        Elements companyTimes = elem.getElementsByClass(className);
        return companyTimes != null && companyTimes.size() > 0 ? companyTimes.get(0).text() : "";
    }

    private static String getTextById(Element elem, String idName) {
        if (elem == null || StringUtils.isBlank(idName)) {
            return "";
        }
        Element element = elem.getElementById(idName);
        return element != null ? element.text() : "";
    }

    public static String parseContent(ResumeDetail resumeDetail) {
        if (resumeDetail == null) {
            return "";
        }
        String job = resumeDetail.getJob();
        ResumeUser user = resumeDetail.getUser();
        String tech = resumeDetail.getProfessionalSkills();
        String summary = resumeDetail.getPersonalSummary();
        String extend = resumeDetail.getExtend();
        List<ResumeEducation> educations = resumeDetail.getEducations();
        List<ResumeCompany> companies = resumeDetail.getCompanies();
        List<ResumeProject> projects = resumeDetail.getProjects();
        StringBuffer content = new StringBuffer();
        content.append("应用岗位信息:" + job).append("\n");
        content.append("\n");
        content.append("应聘人基础信息").append("\n")
                .append("姓名:").append(user.getName()).append("\n")
                .append("一句话介绍自己:").append(user.getDesc()).append("\n")
                .append("其他信息:").append(user.getBaseInfo()).append("\n")
                .append("手机号:").append(user.getPhone()).append("\n")
                .append("邮箱:").append(user.getEmail()).append("\n")
                .append("个人总结/个人补充信息:").append(summary).append("\n")
                .append("专业技能/学业信息:").append(tech).append("\n").append("\n")
                .append("补充内容:").append(extend).append("\n").append("\n");
        if (CollectionUtils.isNotEmpty(educations)) {
            content.append("\n");
            content.append("学位信息").append("\n");
            for (int i = 0; i < educations.size(); i++) {
                int idx = i + 1;
                ResumeEducation education = educations.get(i);
                if (idx == 2 && (education.getSchool().equals("学校名称") ||
                        education.getEducationTime().equals("毕业时间"))) {
                    // 系统Mock学历2数据不参与
                    continue;
                }
                content.append("学历" + idx + ":").append(education.getEducation()).append("\n")
                        .append("学校" + idx + ":").append(education.getSchool()).append("\n")
                        .append("专业" + idx + ":").append(education.getSpeciality()).append("\n")
                        .append("时间" + idx + ":").append(education.getEducationTime()).append("\n");
            }
        }
        if (CollectionUtils.isNotEmpty(companies)) {
            content.append("\n");
            content.append("履历/过往呆过的公司信息").append("\n");
            for (int i = 0; i < companies.size(); i++) {
                int idx = i + 1;
                ResumeCompany company = companies.get(i);
                content.append("公司基础信息" + idx + ":").append(company.getTime()).append("\n")
                        .append("在该公司的履历简单介绍" + idx + ":").append(company.getJobDesc()).append("\n");
            }
        }
        if (CollectionUtils.isNotEmpty(projects)) {
            content.append("\n");
            content.append("项目经验").append("\n");
            for (int i = 0; i < projects.size(); i++) {
                int idx = i + 1;
                ResumeProject project = projects.get(i);
                content.append("第"+idx+"个项目信息:").append("\n");
                content.append("项目名:").append(project.getName()).append("\n")
                        .append("我在项目中的角色:").append(project.getRole()).append("\n")
                        .append("参与时间:").append(project.getTime()).append("\n")
                        .append("项目技术栈:").append(project.getTech()).append("\n")
                        .append("项目简介:").append(project.getDesc()).append("\n")
                        .append("我在项目中的工作内容:").append(project.getWorkContent()).append("\n")
                        .append("项目收益/我的成长/项目的难点与解决方案:").append(project.getIncome()).append("\n");
            }
        }
        return content.toString();
    }

    /**
     * 获取项目JSON模版
     *
     * @return
     */
    public static String getJianLiJsonTemplate() {
        String job = "应聘岗位信息";
        String tech = "专业技能/学业信息 务必返回字符串不要数组结构";
        String summary = "个人总结/个人补充信息";
        ResumeUser resumeUser = ResumeUser.builder()
                .name("用户姓名")
                .baseInfo("用户基础信息")
                .sex("性别：男 或 女")
                .age(27)
                .address("用户家庭地址信息")
                .desc("一句话介绍自己")
                .phone("手机号")
                .email("邮箱")
                .build();
        List<ResumeEducation> educations = new ArrayList<>();
        educations.add(
                ResumeEducation.builder()
                        .school("教育信息-学校名")
                        .education("教育信息-学历")
                        .speciality("教育信息-专业")
                        .educationTime("教育信息-时间")
                        .build());
        List<ResumeCompany> companies = new ArrayList<>();
        companies.add(ResumeCompany.builder()
                .time("工作履历-时间段 公司名称")
                .jobDesc("工作履历-工作总结")
                .build());
        List<ResumeProject> projects = new ArrayList<>();
        projects.add(ResumeProject.builder()
                .name("项目经验-项目名称")
                .role("项目经验-项目中承担的角色")
                .time("项目经验-项目投入时间")
                .tech("项目经验-项目技术栈")
                .desc("项目经验-项目概述")
                .workContent("项目经验-工作内容")
                .income("项目经验-成长与收获，项目收益等信息")
                .build());
        ResumeDetail resumeDetail = ResumeDetail.builder()
                .job(job)
                .user(resumeUser)
                .professionalSkills(tech)
                .personalSummary(summary)
                .educations(educations)
                .companies(companies)
                .projects(projects)
                .build();
        return JsonUtil.toJsonString(resumeDetail);
    }

    public static String parseHtml(ResumeDetail resume) {
        if (resume == null) {
            return "";
        }

        StringBuffer paper = new StringBuffer("<div id=\"paper-body\">");

        /**
         * 应聘岗位信息
         */
        paper.append(String.format("<div class=\"apply-job-container\"><div id=\"job\" contenteditable=\"true\">应聘岗位：%s</div><select id=\"status\">\n" +
                "                        <option>随时到岗 / 离职</option>\n" +
                "                        <option>月内到岗 / 在职</option>\n" +
                "                        <option>下月到岗 / 在职</option>\n" +
                "                    </select></div>", getDefaultString(resume.getJob(), "编辑岗位信息(所有文字内容都可直接编辑)")));

        /**
         * 用户信息
         */
        paper.append("<div class=\"jianli-title\"><a contenteditable=\"true\">个人资料</a></div>");
        ResumeUser user = resume.getUser() == null ? new ResumeUser() : resume.getUser();
        paper.append("<div class=\"user-base-container\">\n" +
                "            <div class=\"photo-container\">\n" +
                "                <img id=\"photo\" src=\"https://coderutil.oss-cn-beijing.aliyuncs.com/bbs-image/file_6a9f9353be784e64ba9b1492b7ac53bd.png\">\n" +
                "                <div class=\"edit-photo-model\" id=\"edit-photo-model\">\n" +
                "                    <i class=\"layui-icon\" style=\"color: white; font-size: 25px\">&#xe61f;</i><br/>\n" +
                "                    <span style=\"font-size: 14px; color: white\">修改头像</span>\n" +
                "                </div>\n" +
                "            </div>");

        String address = getDefaultString(user.getAddress(), "家庭地址");
        paper.append(String.format("<div id=\"name\" contenteditable=\"true\">%s</div>", getDefaultString(user.getName(), "简历Bot")));
        paper.append(String.format("<div id=\"address\" contenteditable=\"true\">%s岁 %s %s</div>",
                user.getAge() == null ? "x" : user.getAge(),
                getDefaultString(user.getSex(), "男/女"),
                address.substring(0, Math.min(8, address.length()))
        ));
        paper.append(String.format("<div id=\"desc\" contenteditable=\"true\" style=\"width: 550px\">%s</div>", "一句话介绍自己，比如7年Java服务端研发经验, 主要从事内容类产品研发方向"));
        paper.append(String.format("<div class=\"contact-container\">\n" +
                "                <div class=\"contact-item\"><i class=\"layui-icon\">&#xe678;</i><div id=\"phone\" contenteditable=\"true\">%s</div></div>\n" +
                "                <div class=\"contact-item\"><i class=\"layui-icon\">&#xe618;</i><div id=\"email\" contenteditable=\"true\">%s</div></div>\n" +
                "            </div>", getDefaultString(user.getPhone(), "手机号码未配置"), getDefaultString(user.getEmail(), "电子邮件未配置")));
        /**
         * 学历信息
         */
        List<ResumeEducation> educations = resume.getEducations();
        if (CollectionUtils.isEmpty(educations)) {
            // 教育信息为空
            paper.append("<div class=\"education\" id=\"educationCard1\">\n" +
                    "                <div id=\"school\" contenteditable=\"true\" style=\"padding-left: 0px\">学校名称</div>\n" +
                    "                <div class=\"education-info\">\n" +
                    "                    <div id=\"education\" contenteditable=\"true\" style=\"padding-left: 0px\">学历</div>\n" +
                    "                    <div id=\"speciality\" contenteditable=\"true\">专业名称</div>\n" +
                    "                    <div id=\"graduation-time\" contenteditable=\"true\" style=\"border-right: none\">毕业时间</div>\n" +
                    "                </div>\n" +
                    "                <i id=\"ctrlEducationCard1\" class=\"layui-icon ctrl-education\" onclick=\"$('#educationCard2').show()\">&#xe61f;</i>\n" +
                    "            </div>" +
                    "<div class=\"education\" id=\"educationCard2\" style=\"display: none;\">\n" +
                    "                <div id=\"school2\" contenteditable=\"true\" style=\"padding-left: 0px;\">学校名称2</div>\n" +
                    "                <div class=\"education-info\">\n" +
                    "                    <div id=\"education2\" contenteditable=\"true\" style=\"padding-left: 0px;\">学历2</div>\n" +
                    "                    <div id=\"speciality2\" contenteditable=\"true\">专业名称2</div>\n" +
                    "                    <div id=\"graduation-time2\" contenteditable=\"true\" style=\"border-right: none\">毕业时间2</div>\n" +
                    "                </div>\n" +
                    "                <i id=\"ctrlEducationCard2\" class=\"layui-icon ctrl-education\">&#xe616;</i>\n" +
                    "            </div>");
        } else {
            for (int i = 0; i < educations.size(); i++) {
                ResumeEducation education = educations.get(i);
                String cardStyle = "";
                String borderStyle = "";
                String schroolBorderStyle = "";
                String icon = i == 1 ? "&#xe616;" : "&#xe61f;";
                paper.append(String.format("<div class=\"education\" id=\"educationCard%s\" %s>\n" +
                        "                <div id=\"school%s\" contenteditable=\"true\" style=\"padding-left: 0px; %s\">%s</div>\n" +
                        "                <div class=\"education-info\">\n" +
                        "                    <div id=\"education%s\" contenteditable=\"true\" style=\"padding-left: 0px; %s\">%s</div>\n" +
                        "                    <div id=\"speciality%s\" contenteditable=\"true\" style=\"%s\">%s</div>\n" +
                        "                    <div id=\"graduation-time%s\" contenteditable=\"true\" style=\"border-right: none\">%s</div>\n" +
                        "                </div>\n" +
                        "                <i id=\"ctrlEducationCard%s\" class=\"layui-icon ctrl-education\" onclick=\"$('#educationCard2').show()\">%s</i>\n" +
                        "            </div>",
                        (i + 1), cardStyle,
                        i == 0 ? "" : (i + 1), schroolBorderStyle, getDefaultString(education.getSchool(), "学校名称"),
                        i == 0 ? "" : (i + 1), borderStyle, getDefaultString(education.getEducation(), "学历"),
                        i == 0 ? "" : (i + 1), borderStyle, getDefaultString(education.getSpeciality(), "专业名称"),
                        i == 0 ? "" : (i + 1), getDefaultString(education.getEducationTime(), "毕业时间"),
                        (i + 1), icon));

            }
            if (educations.size() == 1) {
                paper.append("<div class=\"education\" id=\"educationCard2\" style=\"display: none;\">\n" +
                        "                <div id=\"school2\" contenteditable=\"true\" style=\"padding-left: 0px;\">学校名称2</div>\n" +
                        "                <div class=\"education-info\">\n" +
                        "                    <div id=\"education2\" contenteditable=\"true\" style=\"padding-left: 0px;\">学历2</div>\n" +
                        "                    <div id=\"speciality2\" contenteditable=\"true\" >专业名称2</div>\n" +
                        "                    <div id=\"graduation-time2\" contenteditable=\"true\" style=\"border-right: none\">毕业时间2</div>\n" +
                        "                </div>\n" +
                        "                <i id=\"ctrlEducationCard2\" class=\"layui-icon ctrl-education\">&#xe616;</i>\n" +
                        "            </div>");
            }
        }
        paper.append("</div>");

        /**
         * 专业技能
         */
        paper.append("<div class=\"jl-item\"><div class=\"jianli-title\"><a contenteditable=\"true\">专业技能</a></div>");
        paper.append(String.format("<div id=\"tech\" contenteditable=\"true\">%s</div><i class=\"sort-item layui-icon\">&#xe671;</i></div>", getDefaultString(resume.getProfessionalSkills(), "专业技能描述，比如精通java、Vue……")));

        /**
         * 工作履历
         */
        paper.append("<div class=\"jl-item\"><div class=\"jianli-title\" id=\"lvli\">\n" +
                "            <a contenteditable=\"true\">工作履历</a>\n" +
                "            <button id=\"addLvLi\"><i class=\"layui-icon\">&#xe654;</i> 添加履历</button>\n" +
                "        </div>");
        paper.append("<div class=\"company-times\">\n" +
                "            <ul class=\"layui-timeline\" style=\"text-align: left; margin-bottom: -20px\" id=\"companys\">");
        List<ResumeCompany> companies = resume.getCompanies();
        if (CollectionUtils.isEmpty(companies)) {
            paper.append("<li class=\"companyItem layui-timeline-item\">\n" +
                    "                    <i class=\"layui-icon layui-timeline-axis\">\uE63F</i>\n" +
                    "                    <div class=\"layui-timeline-content layui-text\">\n" +
                    "                        <h3 class=\"layui-timeline-title\" contenteditable=\"true\">工作时间 例如：2019年 ～ 2024年</h3>\n" +
                    "                        <p class=\"companyJobDesc\" contenteditable=\"true\">[公司名称] - [团队名称]\n[任职期间成绩，例如：负责多款**产品的研发工作，任职期间多次获得**之星]</p>\n" +
                    "                        <img class=\"company-logo\" src=\"https://coderutil.oss-cn-beijing.aliyuncs.com/bbs-image/file_788b625640624192b0b2659c2a1473bd.png\">\n" +
                    "                    </div>\n" +
                    "                    <i class=\"delete-item layui-icon\" onmouseover=\"layer.msg('删除该工作经历');\" onmouseout=\"layer.closeAll()\">&#xe640;</i>\n" +
                    "                </li>");
        } else {
            for (ResumeCompany company : companies) {
                paper.append(String.format("<li class=\"companyItem layui-timeline-item\">\n" +
                        "                    <i class=\"layui-icon layui-timeline-axis\">\uE63F</i>\n" +
                        "                    <div class=\"layui-timeline-content layui-text\">\n" +
                        "                        <h3 class=\"layui-timeline-title\" contenteditable=\"true\">%s</h3>\n" +
                        "                        <p class=\"companyJobDesc\" contenteditable=\"true\">%s</p>\n" +
                        "                        <img class=\"company-logo\" src=\"https://coderutil.oss-cn-beijing.aliyuncs.com/bbs-image/file_788b625640624192b0b2659c2a1473bd.png\">\n" +
                        "                    </div>\n" +
                        "                    <i class=\"delete-item layui-icon\" onmouseover=\"layer.msg('删除该工作经历');\" onmouseout=\"layer.closeAll()\">&#xe640;</i>\n" +
                        "                </li>",
                        getDefaultString(company.getTime(), "工作时间 例如：2019年 ～ 2024年"),
                        getDefaultString(company.getJobDesc(), "[公司名称] - [团队名称]\n[任职期间成绩，例如：负责多款**产品的研发工作，任职期间多次获得**之星]")));
            }
        }
        paper.append("</ul>" +
                "        </div><i class=\"sort-item layui-icon\">&#xe671;</i></div>");

        /**
         * 项目经验
         */
        paper.append("<div class=\"jl-item\"><div class=\"jianli-title\" id=\"jingyan\">\n" +
                "            <a contenteditable=\"true\">项目经验</a>\n" +
                "            <button id=\"addJingYan\"><i class=\"layui-icon\">&#xe654;</i> 添加经验</button>\n" +
                "        </div>");

        paper.append("<div id=\"jingyans\">");

        List<ResumeProject> projects = resume.getProjects();
        if (CollectionUtils.isEmpty(projects)) {
            paper.append("<div class=\"jingyan-item\" contenteditable=\"true\">\n" +
                    "                <div class=\"jingyan-header\">\n" +
                    "                    <div class=\"jingyan-name\" contenteditable=\"true\">项目名</div>\n" +
                    "                    <div class=\"jingyan-role\" contenteditable=\"true\">研发负责人</div>\n" +
                    "                    <div class=\"jingyan-time\" contenteditable=\"true\">时间</div>\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                    "                    技术栈\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-content projectTech\" contenteditable=\"true\">\n" +
                    "                    JDK17 + SpringBoot3.0 + SpringCloud + JPA + MySQL + Redis\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                    "                    项目简介\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-content projectDesc\" contenteditable=\"true\">\n" +
                    "                    以兰花为媒介，制定行业整合平台，去除传统绿植赚取差价的思维模式，将农业市场带向资本市场。将线下的批发行业转战至线上，为线下传统行业提供沟通和链接的平台。解决传统行业人脉滞留单一的痛点，并改变相似行业的竞价关系为合作关系。\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                    "                    我的职责\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-content projectWorkContent\" contenteditable=\"true\">\n" +
                    "                    担任项目中产品经理，负责产品战略规划、竞品分析，Axure原型设计，需求文档撰写，项目进程管理、沟通UI、前端、开发、测试及运营，参与产品上线前终测及产品上线后运营与负责新功能迭代。\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                    "                    难点与成长\n" +
                    "                </div>\n" +
                    "                <div class=\"jingyan-content projectIncome\" contenteditable=\"true\">\n" +
                    "                    担任项目中产品经理，负责产品战略规划、竞品分析，Axure原型设计，需求文档撰写，项目进程管理、沟通UI、前端、开发、测试及运营，参与产品上线前终测及产品上线后运营与负责新功能迭代。\n" +
                    "                </div>\n" +
                    "                <i class=\"delete-jingyan-item layui-icon\" onmouseover=\"layer.msg('删除该项目');\" onmouseout=\"layer.closeAll()\">&#xe640;</i>\n" +
                    "            </div>");
        } else {
            for (int i = 0; i < projects.size(); i++) {
                ResumeProject project = projects.get(i);
                paper.append(String.format("<div class=\"jingyan-item\" contenteditable=\"true\">\n" +
                        "                <div class=\"jingyan-header\">\n" +
                        "                    <div class=\"jingyan-name\" contenteditable=\"true\">%s</div>\n" +
                        "                    <div class=\"jingyan-role\" contenteditable=\"true\">%s</div>\n" +
                        "                    <div class=\"jingyan-time\" contenteditable=\"true\">%s</div>\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                        "                    技术栈\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-content projectTech\" contenteditable=\"true\">\n" +
                        "                    %s \n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                        "                    项目简介\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-content projectDesc\" contenteditable=\"true\">\n" +
                        "                    %s\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                        "                    我的职责\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-content projectWorkContent\" contenteditable=\"true\">\n" +
                        "                    %s\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-title\" contenteditable=\"true\">\n" +
                        "                    难点与成长\n" +
                        "                </div>\n" +
                        "                <div class=\"jingyan-content projectIncome\" contenteditable=\"true\">\n" +
                        "                    %s\n" +
                        "                </div>\n" +
                        "                <i class=\"delete-jingyan-item layui-icon\" onmouseover=\"layer.msg('删除该项目');\" onmouseout=\"layer.closeAll()\">&#xe640;</i>\n" +
                        "            </div>",
                        getDefaultString(project.getName(), "项目名"),
                        getDefaultString(project.getRole(), "研发负责人"),
                        getDefaultString(project.getTime(), "时间"),
                        getDefaultString(project.getTech(), "技术栈，例如：JDK17 + SpringBoot3.0 + SpringCloud + JPA + MySQL + Redis"),
                        getDefaultString(project.getDesc(), "项目描述，例如：简历Bot是一个助力用户方便制作高质量的简历平台，在这里可以很容易的创建一份简历、并且有AI诊断、智能证件照、抠图等功能"),
                        getDefaultString(project.getWorkContent(), "我的职责：例如：担任项目中产品经理，负责产品战略规划、竞品分析，Axure原型设计，需求文档撰写，项目进程管理、沟通UI、前端、开发、测试及运营，参与产品上线前终测及产品上线后运营与负责新功能迭代。"),
                        getDefaultString(project.getIncome(), "难点与成长 例如：AI助理分析简历，智能诊断如何输出更个性化、准确的结果难题中，我通过XX的方式，达到了什么样的预期等")));
            }
        }
        paper.append("</div><i class=\"sort-item layui-icon\">&#xe671;</i></div>");
        /**
         * 个人总结
         */
        paper.append("<div class=\"jl-item\"><div class=\"jl-item\">\n" +
                "                <div class=\"jianli-title\" id=\"extend-title\">\n" +
                "                    <a contenteditable=\"true\">扩展模块（可删除）</a>\n" +
                "                    <button id=\"deleteItem\"><i class=\"layui-icon\">&#xe654;</i> 删除模块</button>\n" +
                "                </div>\n" +
                "                <div id=\"extend\" contenteditable=\"true\">" +getDefaultString(resume.getExtend(), "[比如获奖证书等信息]") +"</div>\n" +
                "                <i class=\"sort-item layui-icon\">&#xe671;</i>\n" +
                "            </div><i class=\"sort-item layui-icon\">&#xe671;</i></div>");
        /**
         * 个人总结
         */
        paper.append("<div class=\"jl-item\"><div class=\"jianli-title\">\n" +
                "            <a contenteditable=\"true\">个人总结</a>\n" +
                "        </div>");
        paper.append(String.format("<div id=\"summary\" contenteditable=\"true\">%s</div>",
                getDefaultString(resume.getPersonalSummary(), "[个人总结内容，例如：性格开朗、积极拥抱变化等等]")));

        paper.append("</div><i class=\"sort-item layui-icon\">&#xe671;</i></div>");
        return paper.toString();
    }

    private static String getDefaultString(String obj, String defaultValue) {
        return StringUtils.isBlank(obj) ? defaultValue : obj;
    }

    public static void main(String[] args) {
        System.out.println(getJianLiJsonTemplate());
    }
}
